/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vectors.MultiThreding;

import Vectors.IVector;
import Vectors.Keeper;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author netcracker
 */
public class OneWriteThread implements Runnable {

    Keeper keeper;
    Random r = new Random();

    public OneWriteThread(Keeper aThis) {
        this.keeper = aThis;
    }

    @Override
    public synchronized void run() {

        for (int i = 0; i < keeper.getLength(); i++) {
            while (keeper.isEdited()) {
                Thread.yield();
            }
            keeper.set(r.nextDouble(), i);
            System.out.println("Write: " + keeper.get(i) + " on position " + i);
            keeper.setEdited(true);
            notifyAll();
        }
    }
}
